<?php

 include('./mod_config.php');
/* 优化数据表 */
 if ($_POST)
 {
	/* 返回表名 */
	 $tables = getTables( $conf["Database"]);
	 foreach ($tables as $value)
	 {
	   $query = "OPTIMIZE TABLE " . $value;
	   if (! mysql_query($query))
	   {
         MyNotice('優化失敗' . $value);
		 exit(0);
	   }
	 }
	 MyNotice('優化數據表成功',2,"optimize.php");
	 exit(0);
 }

//Tpl
 $tpl -> set_file("main", "optimize.htm");
 $tpl -> set_block('main', 'TBL_LIST', 'tbl_list');  //数据表列表

/* 初始化数据 */
 $list = array();
 $num = 0;

 $res = mysql_query("SHOW TABLE STATUS");
 while ($ret = mysql_fetch_array($res))
 {
	$list = array(
		             'tbl_name'=>$ret['Name'], 
		             'tbl_record'=>$ret['Rows'], 
		             'tbl_size' =>num_bitunit($ret['Data_length']) , 
		             'tbl_index' => $ret['Index_length'] , 
		             'tbl_chip'=>$ret['Data_free'] 
		            );
	$tpl -> set_var($list);
	$tpl -> parse('tbl_list', 'TBL_LIST', true);
	$num += $ret['Data_free'];
 }
 unset($ret);
 $tpl -> set_var(array(
                        'admin_url' => $admin_url
                       ));
 $tpl -> parse("Out_main", "main");
 $tpl -> p("Out_main");

?>